/* calculator. by: michael steer. 165th program wrote,  18/05/2011

VERSION 1.00

written for lane sabo to use as a reference. covers variables, control, functions, 
touches on pointers(&VARIABLE), variable manipulation, input and output and 
the basics */

//lane, anything wit a double backslash following it is a comment. such as this sentance
/* you can make comments like so with an asterik and a slash that cover more then one line */



#include <iostream> // includes the functions cout, cin, and others
using namespace std; // makes it so for every iostream command; you dont have to go "std::cout"



/* NOTICE THE & symbol after the "int& z". thats called a reference operator
	for normal functions, you have to RETURN something to make a variable change.
	with this function. you pass the answer variable; c into this function. normally
	you would have to go return z; and wherever this function is used you would have
	to go c = add(x,y) but INSTEAD with the int& z. it uses the actual c variable 
	with a different name. so when you go z = something c will also change without
	having to do anything. if this doesnt make sense ignore it*/
void get_input(float& x, float& y)
{
	cout << "enter a number:" << endl;
	cin >> x;
	cout << "\nenter another number" << endl;
	cin >> y;
} // gets input from the keyboard.
void answer(float z)
{
	cout << "answer is:" << z << endl;
} // prints your answer to the screen
void add(float x, float y, float& z)
{
	z=x+y;
} // adds 2 variables
void subtract(float x, float y, float& z)
{
	z=x-y; 
}// subtracts 2 numbers
void multiply(float x, float y, float& z)
{
	z=x*y;
} // multiplies 2 numbers
void devide(float x, float y, float& z)
{
	z=x/y;
} // devides 2 numbers
/*void modulous(float x, float y, float& z)
{
	z=x%y;
} // returns the remainder of 2 numbers devided */
int factorial (float a)
{
if (a > 1) // checks to see if its done yet. if you start at 5 the function counts down 5,4,3,2,1
return (a * factorial (a-1)); // recursion, a function calling itself. if its not done it goes onto the next step
else // if it IS done
return (1); // returns 1 and stops the function
} // returns !x. if x is say y then !5 is 5*4*3*2*1
int main()
{
	cout << "welcome to michaels demo calculator" << endl; // prints a welcome message
	float a=0, b=0, c=0;
	int choice=0, exit=0; //makes 2 variables for input, one for output, one for choosing, and one for exiting
	while (exit != 1) // if exit doesnt equal 1 it starts over again
	{

		 // writes menu on the screen
		cout << "enter a choice;" << endl;
		cout << "1: add. 2: subtract. 3: multiply. 4: devide" << endl;
		cout << "5: devide(remainder). 6: factorial. 7: quit" << endl;
		cin >> choice; // gets your choice from the keyboard
		switch (choice) // a modified IF statement
		{
		case 1: // you pressed one
			get_input(a, b); // gets input, adds, and gives you an answer
			add(a, b, c);
			answer(c);
			break; // skips other cases so u dont have wierd crap going on
		case 2: // if you pressed two
			get_input(a, b); // gets input, subtracts, gives you an answer
			subtract(a, b, c);
			answer(c);
			break;
		case 3: // if you pressed three
			get_input(a, b); // gets input, multiplies, and gives you an answer
			multiply(a, b, c);
			answer(c);
			break;
		case 4: // if you pressed four
			get_input(a, b); // gets input, devides, gives you an answer
			devide(a, b, c);
			answer(c);
			break;
		case 5: // if you pressed five
			cout << "**not done" << endl;
			//get_input(a, b); //gets input, uses the % thingy, gives u an answer
			//modulous(a, b, c);
			//answer(c);
			break;
		case 6: // if you pressed 6
			cout << "enter a number, the second number MUST be a zero" << endl; // you only need one number for factorials
			get_input(a, b); // it still gets 2 numbers, it only uses one. this saves time
			c = factorial(a); // makes c equal to the factorial of a
			answer(c); // answers with c
			break;
		case 7: // if you pressed 7
			exit = 1; // makes exit 1 so when you get to the start of the wile loop it quits
			break;
		case 8: // hehe :)
			cout << "your gay :)" << endl;
		}
	}
	return 0;
} // the main function
